#include<stdio.h>

/*c语言操作学习第5课：文件读取（fread）*/

int main()
{
    FILE *file = fopen("../Files/test-2-UTF8.txt","r");//使用相对路径
    char arr[1024];

    char *str;

    while ((str = fgets(arr,1024,file)) != NULL)//使用fgets读取文件直到结束
    {
        printf("%s",str);
    }
    fclose(file);//关闭文件
    

    FILE *story = fopen("../Files/test-3-UTF8.txt","r");
    int n = fread(arr,1,1024,file);//只读取了1024个字节

    printf("n=%d\n",n);//共读取了多少字节
    
    printf("%s",arr);
    fclose(story);//关闭文件

    FILE *storyagain = fopen("../Files/test-3-UTF8.txt","r");
    n = 0;
    while ((n = fread(arr,1,100,storyagain)) != 0)//每次读取10个字节，直到文件结束
    {
        for (int i = 0; i < n; i++)
        {
            printf("%c",arr[i]);
        }
        
    }
    fclose(storyagain);//关闭文件

    return 0;
}